#include<iostream>
#include<sys/types.h>
#include<sys/select.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>

#define  BACK_LOG 5
using std::cout;
using std::endl;


namespace SockEtta
{
  class Se_Sock
  {
    public:
    static int Sock()
    {
      int sock=socket(AF_INET,SOCK_STREAM,0);
      if(sock<0)
      {
        cout<<"socket error"<<endl;
        exit(1);
      }
      return sock;
     }
    static bool Bind(int sock,unsigned short port)
    {
      struct sockaddr_in local;
      local.sin_family=AF_INET;
      local.sin_addr.s_addr=INADDR_ANY;
      local.sin_port=htons(port);
      socklen_t len=sizeof(local);
      if(bind(sock,(struct sockaddr*)&local,len)<0)
      {
        cout<<"bind error"<<endl;
        exit(2);
      }
      return true;
    }
    static int Listen_sock(int sock)
    {
      int listen_sock=  listen(sock,BACK_LOG);
      if(listen_sock<0)
      {
        cout<<"listen error"<<endl;
        exit(3);
      }
      return listen_sock;
    }
  };
}
